<%-- 
    Document   : index
    Created on : 2009-12-12, 10:59:17
    Author     : Administrator
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="javax.mail.*,javax.mail.internet.*, javax.activation.*, javax.naming.InitialContext" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%
    String toAddress = request.getParameter("MailTo");
    String fromAddress = request.getParameter("MailFrom");
    String subject = request.getParameter("MailSubject");
    String content = request.getParameter("MailContent");
    InitialContext context = new InitialContext();
    Session sessions = (Session) context.lookup("java:/tourMail");
    if (toAddress != null && !toAddress.equals(""));
    {
      try
      {
        MimeMessage msg = new MimeMessage(sessions);
        msg.setFrom(new InternetAddress(fromAddress));
        msg.setRecipients(javax.mail.Message.RecipientType.TO, toAddress);
        msg.setSubject(subject);
        msg.setSentDate(new java.util.Date());
        Multipart mulitpt = new MimeMultipart();
        MimeBodyPart bodyPart = new MimeBodyPart();
        bodyPart.setContent(content, "text/plain");
        mulitpt.addBodyPart(bodyPart);
        msg.setContent(mulitpt);
        Transport.send(msg);
        System.out.println("Send Mail OK!");
      }
      catch(MessagingException me)
      {
        me.printStackTrace();
      }

      }
%>
<HTML>
<BODY BGCOLOR="white">
<form METHOD="POST" ACTION="mail.jsp">
 <table CELLSPACING="0" CELLPADDING="3" BORDER="1" WIDTH="474">
    <tr>
      <td width="150"><div align="left">From :</small></td>
      <td width="324"><input TYPE="TEXT" name="MailFrom" value=""></td>
    </tr>
    <tr>
      <td width="150"><div align="left">To :</small></td>
      <td width="324"><input TYPE="TEXT" name="MailTo" value=""></td>
    </tr>
    <tr>
      <td width="150"><div align="left">Subject :</small></td>
      <td width="324"><input TYPE="TEXT" name="MailSubject" value=""></td>
    </tr>
    <tr>
      <td width="150"><div align="left">Content :</small></td>
      <td width="324"><TEXTAREA cols=50 name="MailContent" rows=8></TEXTAREA></td>
    </tr>
    <tr>
      <td></td>
      <td colspan="2" width="474"><input TYPE="Submit"></td>
    </tr>
 </table>
</form>
</BODY>
</HTML>
